package cn.xaut.剑指offer.m20;


import java.util.Stack;

/**
 * 剑指 Offer 27. 二叉树的镜像
 */
public class demo27 {

    // 利用栈
    public TreeNode mirrorTree(TreeNode root) {

        if (root == null)
            return null;

        Stack<TreeNode> stack = new Stack<>();
        stack.push(root);
        while (!stack.isEmpty()) {
            TreeNode node = stack.pop();
            if (node.left != null)
                stack.push(node.left);
            if (node.right != null)
                stack.push(node.right);
            TreeNode temp = node.left;
            node.left = node.right;
            node.right = temp;
        }
        return root;
    }
}
